/**
 *  *2010-3-25 下午12:56:12  add 
 */
package com.base.myproject.server.Comet;

import java.util.HashMap;
import java.util.Vector;

/**
 * Comet对象的容器
 * 
 * @author Administrator
 *2010-3-25
 * javazgw@gmail.com
 */
public class CometContainer implements Runnable{


	Vector<CometObject> v = new Vector<CometObject>();
	public HashMap<String ,String> ht = new HashMap<String,String>();
	
	private CometContainer ()
	{
		
	}
	
	public static CometContainer cc = null;
	public static CometContainer getInstance()
	{
		if(cc==null)
		{
			cc =new CometContainer();
		}
		return cc;
	}
	@Override
	public void run() {
		while(true)
		{
		for(CometObject co:v)
		{

			if(co.getState().equals(Thread.State.NEW))
			{
				co.start();
			}
			else	if(co.getState().equals(Thread.State.WAITING))
			{
				synchronized (co) {
					co.notify();
				}
				
			}
//			co.
		}
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		
	
		
	}
	public void add(CometObject co)
	{
		v.add(co);
		
	}
	public void remove(CometObject co)
	{
		v.remove(co);
	}

	static boolean b = false;
	public static  void test()
	{
		if(!b)
		{
			b=true;
		//CometContainer cc=	new CometContainer();
		new Reservation(getInstance());
		Thread t1 = new Thread(getInstance());
		t1.start();
		}
	}
	public static void main(String[] argv)
	{
		
//		CometContainer cc=	new CometContainer();
//		new Reservation(cc);
//		new Test(cc);
		
		test();
//		Thread t1 = new Thread(cc);
//		t1.start();
		

		
	}
}
